PowerSNMP for .NET CF
Marshal(String,Variable[,],Object) Method
See Also  Example Send comments on this topic.
Dart.Snmp Namespace > Manager Class > Marshal Method : Marshal(String,Variable[,],Object) Method




oid
The oid of the table used in ManagerSlave.GetTable or ManagerSlave.GetTable.
table
Array of table variables to be marshaled.
state
User state information passes to Marshal.
Marshals an array of table variables to the UI thread.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub Marshal( _
   ByVal oid As String, _
   ByVal table(,) As Variable, _
   ByVal state As Object _
) 
Visual Basic (Usage)Copy Code
Dim instance As Manager
Dim oid As String
Dim table() As Variable
Dim state As Object
 
instance.Marshal(oid, table, state)
C# 
public void Marshal( 
   string oid,
   Variable[,] table,
   object state
)
Managed Extensions for C++ 
public: void Marshal( 
   string* oid,
   Variable*[,]* table,
   Object* state
) 
C++/CLI 
public:
void Marshal( 
   String^ oid,
   array<Variable^>^ table,
   Object^ state
) 

Parameters

oid
The oid of the table used in ManagerSlave.GetTable or ManagerSlave.GetTable.
table
Array of table variables to be marshaled.
state
User state information passes to Marshal.

Example

The following example demonstrates how to retrieve a table using internal GetBulk requests to retrieve 20 cells at a time.
C#Copy Code
private void button1_Click(object sender, EventArgs e)
{
    //Retrieve and display an SNMP Table
    manager1.Start(getTable, myAgentAddress);
}

private void getTable(ManagerSlave slave, object state)
{
    //Get SNMP ifTable at specified address
    string address = state.ToString();
    slave.Socket.ReceiveTimeout = 3000;
    
    //Retrieve table using GetBulk with 20 max-repetitions
    Variable[,] table = slave.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, SnmpVersion.Two, "public", null,
        new System.Net.IPEndPoint(System.Net.IPAddress.Parse(address), 161), 20);

    //Marshal table to UI thread
    manager1.Marshal(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, table, null);
}

void manager1_Table(object sender, Dart.Snmp.TableEventArgs e)
{
    buildTable(e.Table);
}

private void buildTable(Variable[,] table)
{
    //Add columns to the listview for each column in the table
    for (int i = 0; i < table.GetLength(1); i++)
        lvwTable.Columns.Add("Column " + (i + 1).ToString(), 100, HorizontalAlignment.Left);

    ListViewItem tableRow;
    int r, c = 0;
    for (r = 0; r < table.GetLength(0); r++)
    {
        //Create a new row and add the first cell
        tableRow = new ListViewItem(table[r, 0].Value.ToString());

        //Add each additional cell in the row
        for (c = 1; c < table.GetLength(1); c++)
            tableRow.SubItems.Add((table[r, c] == null) ? "NULL" : table[r, c].Value.ToString());

        //Add the row to the listview
        lvwTable.Items.Add(tableRow);
    }
}
Visual BasicCopy Code
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Retrieve and display an SNMP Table
    manager1.Start(AddressOf getTable, myAgentAddress)
End Sub

Private Sub getTable(ByVal slave As ManagerSlave, ByVal state As Object)
    'Get SNMP ifTable at specified address
    Dim address As String = state.ToString()
    slave.Socket.ReceiveTimeout = 3000

    //Retrieve table using GetBulk with 20 max-repetitions
    Dim table(,) As Variable = slave.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, _
        SnmpVersion.Two, "public", Nothing, New System.Net.IPEndPoint(System.Net.IPAddress.Parse(address), 161), 20)

    'Marshal table to UI thread
    manager1.Marshal(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, table, Nothing)
End Sub

Private Sub manager1_Table(ByVal sender As Object, ByVal e As Dart.Snmp.TableEventArgs)
    buildTable(e.Table)
End Sub

Private Sub buildTable(ByVal table(,) As Variable)
    'Add columns to the listview for each column in the table
    For i As Integer = 0 To table.GetLength(1) - 1
        lvwTable.Columns.Add("Column " & (i + 1).ToString(), 100, HorizontalAlignment.Left)
    Next i

    Dim tableRow As ListViewItem
    Dim r As Integer, c As Integer = 0
    For r = 0 To table.GetLength(0) - 1
        'Create a new row and add the first cell
        tableRow = New ListViewItem(table(r, 0).Value.ToString())

        'Add each additional cell in the row
        For c = 1 To table.GetLength(1) - 1
            If (table(r, c) Is Nothing) Then
                tableRow.SubItems.Add("NULL")
            Else
                tableRow.SubItems.Add(table(r, c).Value.ToString())
            End If
        Next c

        'Add the row to the listview
        lvwTable.Items.Add(tableRow)
    Next r
End Sub

Remarks

This method can be used to marshal table information from a worker thread to the UI thread for typical display purposes. It calls OnTable on the UI thread, which raises the Table event.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.